home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / What's New? / Development Kits / Mac OS / USB DDK 1.4.6f4 / Examples / DropPrint•USB / DropShell.c < prev    next >
Encoding:
Text File  |  2000-09-25  |  6.8 KB  |  298 lines  |  [TEXT/R*ch]

  1. /*
  2.     File:        DropShell.c
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 2000 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. /******************************************************************************
  13. **
  14. **  Project Name:    DropShell
  15. **     File Name:    DropShell.c
  16. **
  17. **   Description:    Main application code for the QuickShell
  18. **
  19. *******************************************************************************
  20. **                       A U T H O R   I D E N T I T Y
  21. *******************************************************************************
  22. **
  23. **    Initials    Name
  24. **    --------    -----------------------------------------------
  25. **    LDR            Leonard Rosenthol
  26. **    MTC            Marshall Clow
  27. **    SCS            Stephan Somogyi
  28. **
  29. *******************************************************************************
  30. **                      R E V I S I O N   H I S T O R Y
  31. *******************************************************************************
  32. **
  33. **      Date        Author    Description
  34. **    ---------    ------    ---------------------------------------------
  35. **    23 Jun    94    LDR        Implemented support for disk insertion events
  36. **    02 Feb    94    LDR        Updated for Final SDK & CodeWarrior a2
  37. **                        Removed the ResumeProc as per new Apple recommendations
  38. **    11 Dec 93    SCS        Universal Headers/UPPs (Phoenix 68k/PPC & PPCC)
  39. **                        Skipped System 6 compatible rev of DropShell source
  40. **    09 Dec 91    LDR        Added support for new "Select File…" menu item
  41. **                        Quit now sends AEVT to self to be politically correct
  42. **                        Added support for the new gSplashScreen
  43. **    24 Nov 91    LDR        Added support for the Apple Menu (duh!)
  44. **    29 Oct 91    SCS        Changes for THINK C 5
  45. **    28 Oct 91    LDR        Officially renamed DropShell (from QuickShell)
  46. **                        Added a bunch of comments for clarification
  47. **    06 Oct 91    MTC        Converted to MPW C
  48. **    09 Apr 91    LDR        Added to Projector
  49. **
  50. ******************************************************************************/
  51.  
  52. //#ifndef __MWERKS__
  53. //#include <Desk.h>
  54. #include <Dialogs.h>
  55. #include <Errors.h>
  56. #include <Files.h>
  57. #include <Fonts.h>
  58. #include <Memory.h>
  59. #include <Menus.h>
  60. #include <StandardFile.h>
  61. #include <TextEdit.h>
  62. #include <Types.h>
  63. #include <Windows.h>
  64. #include <DiskInit.h>
  65. #include <Devices.h>
  66. //#endif
  67.  
  68. #include "DSGlobals.h"
  69. #include "DSUserProcs.h"
  70. #include "DSAppleEvents.h"
  71.  
  72. #include "DropShell.h"
  73.  
  74.  
  75.  
  76. Boolean        gDone, gOApped, gHasAppleEvents, gWasEvent;
  77. EventRecord    gEvent;
  78. MenuHandle    gAppleMenu, gFileMenu;
  79. WindowPtr    gSplashScreen;
  80. QDGlobals    qd;
  81.  
  82. #ifdef MPW
  83. extern void _DataInit();    
  84. #endif
  85.  
  86.  
  87. #pragma segment Initialize
  88. void InitToolbox (void) 
  89. {
  90.  
  91. #ifdef MPW
  92.     UnloadSeg ((Ptr) _DataInit );
  93. #endif
  94.  
  95.     InitGraf ( &qd.thePort );
  96.     InitFonts ();
  97.     InitWindows ();
  98.     InitMenus ();
  99.     TEInit ();
  100.     InitDialogs (NULL);        // use of ResumeProcs no longer approved by Apple
  101.     InitCursor ();
  102.     FlushEvents ( everyEvent, 0 );
  103.     
  104.     // how about some memory fun! Two should be enough!
  105.     MoreMasters ();
  106.     MoreMasters ();
  107.     }
  108.  
  109. /*
  110.     Let's setup those global variables that the DropShell uses.
  111.     
  112.     If you add any globals for your own use,
  113.     init them in the InitUserGlobals routine in DSUserProcs.c
  114. */
  115. #pragma segment Initialize
  116. Boolean InitGlobals (void) 
  117. {
  118.     long aLong;
  119.  
  120.     gDone            = false;
  121.     gOApped            = false;    // probably not since users are supposed to DROP things!
  122.     gHasAppleEvents    = Gestalt ( gestaltAppleEventsAttr, &aLong ) == noErr;
  123.     gSplashScreen    = NULL;
  124.  
  125.     return(InitUserGlobals());    // call the user proc
  126. }
  127.  
  128. /*
  129.     Again, nothing fancy.  Just setting up the menus.
  130.     
  131.     If you add any menus to your DropBox - insert them here!
  132. */
  133. #pragma segment Initialize
  134. void SetUpMenus (void) {
  135.  
  136.     gAppleMenu = GetMenu ( kAppleNum );
  137.     AppendResMenu ( gAppleMenu, 'DRVR' );
  138.     InsertMenu ( gAppleMenu, 0 );
  139.  
  140.     gFileMenu = GetMenu ( kFileNum );
  141.     InsertMenu ( gFileMenu, 0 );
  142.     DrawMenuBar ();
  143. }
  144.  
  145. /*
  146.     This routine is called during startup to display a splash screen.
  147.     
  148.     This was recommend by the Blue Team HI person, John Sullivan, who
  149.     feels that all apps should display something so that users can easily
  150.     tell what is running, and be able to switch by clicking.  Thanks John!
  151. */
  152. #pragma segment Initialize
  153. void InstallSplashScreen(void) 
  154. {
  155.     #define windowPicID    128
  156.  
  157.     PicHandle    picH;
  158.  
  159.     if (!gSplashScreen) {  // show the splash screen window
  160.         picH = GetPicture(windowPicID);
  161.         if (picH) {
  162.             gSplashScreen = GetNewWindow(windowPicID, NULL, (WindowPtr)-1L);
  163.             if (gSplashScreen) {
  164.                 SetWindowPic(gSplashScreen, picH);
  165.                 // Don't show it here, since we only want to it for oapp launches!
  166.                 // ShowWindow(gSplashScreen);
  167.             }
  168.         }
  169.     }
  170. }
  171.  
  172.  
  173. /*    --------------- Standard Event Handling routines ---------------------- */
  174. #pragma segment Main
  175. void ShowAbout () {
  176.     (void) Alert ( 128, NULL );
  177.     }
  178.  
  179.  
  180. #pragma segment Main
  181. void DoMenu ( long retVal ) {
  182.     short    menuID, itemID;
  183.     Str255    itemStr;
  184.  
  185.     menuID = HiWord ( retVal );
  186.     itemID = LoWord ( retVal );
  187.     
  188.     switch ( menuID ) {
  189.         case kAppleNum:
  190.             if ( itemID == 1 )
  191.                 ShowAbout ();    /*    Show the about box */
  192.             else
  193.             {
  194.                 GetMenuItemText(GetMenuHandle(kAppleNum), itemID, itemStr);
  195.                 OpenDeskAcc(itemStr);
  196.             }
  197.             break;
  198.             
  199.         case kFileNum:
  200.             if ( itemID == 1 )
  201.                 SelectFile();        // call file selection userProc
  202.             else
  203.                 SendQuitToSelf();    // send self a 'quit' event
  204.             break;
  205.         
  206.         default:
  207.             break;
  208.             
  209.         }
  210.     HiliteMenu(0);        // turn it off!
  211.     }
  212.  
  213.  
  214. #pragma segment Main
  215. void DoMouseDown ( EventRecord *curEvent ) {
  216.     WindowPtr    whichWindow;
  217.     short        whichPart;
  218.  
  219.     whichPart = FindWindow ( curEvent->where, &whichWindow );
  220.     switch ( whichPart ) {
  221.         case inMenuBar:
  222.             DoMenu ( MenuSelect ( curEvent->where ));
  223.             break;
  224.         
  225.         case inSysWindow:
  226.             SystemClick ( curEvent, whichWindow );
  227.             break;
  228.         
  229.         case inDrag:
  230.             {
  231.                 Rect    boundsRect = (*GetGrayRgn())->rgnBBox;
  232.                 DragWindow ( whichWindow, curEvent->where, &boundsRect );
  233.             }
  234.         default:
  235.             break;
  236.         }
  237.     }
  238.  
  239.  
  240. #pragma segment Main
  241. void DoKeyDown ( EventRecord *curEvent ) {
  242.     if ( curEvent->modifiers & cmdKey )
  243.         DoMenu ( MenuKey ((char) curEvent->message & charCodeMask ));
  244.     }
  245.  
  246.  
  247.  
  248. #pragma segment Main
  249. void main ( ) 
  250. {
  251.  
  252.     InitToolbox ();
  253.     if ( InitGlobals () ) {    // if we succeeding in initting self
  254.         if ( !gHasAppleEvents )
  255.             ErrorAlert ( kErrStringID, kCantRunErr, 0 );
  256.         else {
  257.             InitAEVTStuff ();
  258.             SetUpMenus ();
  259.             //<oja> InstallSplashScreen ();
  260.             
  261.             while ( !gDone ) {
  262.                 gWasEvent = WaitNextEvent ( everyEvent, &gEvent, 0, NULL );
  263.                 if ( gWasEvent ) {
  264.                     switch ( gEvent.what ) {
  265.                         case kHighLevelEvent:
  266.                             DoHighLevelEvent ( &gEvent );
  267.                             break;
  268.                             
  269.                         case mouseDown:
  270.                             DoMouseDown ( &gEvent );
  271.                             break;
  272.                             
  273.                         case keyDown:
  274.                         case autoKey:
  275.                             DoKeyDown ( &gEvent );
  276.                             break;
  277.  
  278.                         case diskEvt:
  279.                             if (HiWord(gEvent.message)) {
  280.                                 Point diskInitPt;
  281.                                 
  282.                                 diskInitPt.v = diskInitPt.h = 100;
  283.                                 DILoad();
  284.                                 DIBadMount(diskInitPt, gEvent.message);
  285.                                 DIUnload();
  286.                             }
  287.                             break;
  288.                             
  289.                         default:
  290.                             break;
  291.                     }
  292.                 }
  293.             }
  294.         }
  295.         DisposeUserGlobals();    // call the userproc to clean itself up
  296.     }
  297. }
  298.